#!/usr/bin/env coffee
fs = require('fs')
PG = require '../../../../fckoa/db/pg.coffee'
CONFIG = require '../../../config/pg.coffee'
#

do ->
    li = []
    for i in await PG.rows("select schema_name from information_schema.schemata WHERE schema_name NOT IN ('information_schema', 'pg_catalog')")
        li.push i.schema_name

    fs.writeFileSync(
        "#{__dirname}/config.sh"
        """#!/usr/bin/env bash

export PSQL_URL=#{CONFIG}
export PSQL_DB=#{CONFIG.split("/").pop()}
declare -a TABLE_LI=("#{li.join('" "')}")
"""
    )
    process.exit()
